package top.lixunda.ecommerce.server.user.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import top.lixunda.commerce.common.core.entity.MessageObject;
import top.lixunda.ecommerce.server.business.BaseController;
import top.lixunda.ecommerce.server.user.api.controller.IPermissionAllotController;
import top.lixunda.ecommerce.server.user.api.entity.dto.PermissionAllotDTO;
import top.lixunda.ecommerce.server.user.service.IPermissionAllotService;

import java.util.List;

/**
 * 权限分配接口
 *
 * @author Lixunda
 * @since 2020-04-24
 */
@Slf4j
@RestController
public class PermissionAllotController extends BaseController
        implements IPermissionAllotController {

    private final IPermissionAllotService permissionAllotService;

    @Autowired
    public PermissionAllotController(IPermissionAllotService permissionAllotService) {
        this.permissionAllotService = permissionAllotService;
    }

    /**
     * 分配权限
     *
     * @param list 权限操作DTO
     * @return 是否保存成功
     */
    @Override
    public MessageObject<Boolean> allotPermission(List<PermissionAllotDTO> list) {
        Boolean result = permissionAllotService.allotPermission(list);
        return getSuccessMessageObject("添加权限成功", result);
    }

    /**
     * 移除权限
     *
     * @param list 权限操作DTO
     * @return 是否移除成功
     */
    @Override
    public MessageObject<Boolean> removePermission(List<PermissionAllotDTO> list) {
        Boolean result = permissionAllotService.removePermission(list);
        return getSuccessMessageObject("移除权限成功", result);
    }

    /**
     * 根据分配编号移除权限
     *
     * @param list 分配编号列表
     * @return 是否移除成功
     */
    @Override
    public MessageObject<Boolean> removePermissionByIds(List<Integer> list) {
        Boolean result = permissionAllotService.removePermissionByIds(list);
        return getSuccessMessageObject("移除权限成功", result);
    }
}
